/**
 * 
 */
package org.bf.sms.service.login.impl;

import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.bf.sms.domain.user.Account;
import org.bf.sms.exception.SMSException;
import org.bf.sms.persistent.iface.login.DaoAccount;
import org.bf.sms.service.login.LoginService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Login service implementation
 * 
 * @author fantastic
 * @version 1.0 2010-12-9
 * @since 1.0
 */
public class LoginServiceImpl implements LoginService
{
	/** log4j */
	private static final Logger logger = Logger
			.getLogger(LoginServiceImpl.class);

	/** DAO */
	@Autowired
	private DaoAccount daoAccount;

	/**
	 * {@inheritDoc}
	 * 
	 * @throws SMSException
	 * @see org.bf.sms.service.login.LoginService#validate(Account)
	 */
	@Override
	public boolean validate(Account account) throws SMSException
	{
		if (logger.isDebugEnabled())
		{
			logger.debug("account : " + account);
		}

		Account result;
		try
		{
			result = this.daoAccount.query(account.getUsername(),
					account.getPassword());
			if (null != result)
			{
				return true;
			}
		}
		catch (SQLException e)
		{
			logger.error("query error : ", e);
			throw new SMSException("数据库异常,请联系管理员");
		}

		return false;
	}

	/**
	 * @param daoAccount
	 *            the daoAccount to set
	 */
	public void setDaoAccount(DaoAccount daoAccount)
	{
		this.daoAccount = daoAccount;
	}

}
